<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>侧边导航栏 + iframe 布局</title>
    <!-- 引入 Laiyui CSS -->
    <link rel="stylesheet" href="../static/layui-v2.2.5/layui/css/layui.css">
    <style>
        body {
            margin: 0;
            padding: 0;
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
        }

        .container {
            display: flex;
            height: 100vh;
        }

        .sidebar {
            width: 220px;
            background-color: #2c3e50;
            color: white;
            padding: 20px 0;
            box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
        }

        .sidebar-header {
            padding: 0 20px 20px;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
            margin-bottom: 10px;
        }

        .sidebar-nav {
            list-style: none;
            padding: 0;
            margin: 0;
        }

        .sidebar-nav li a {
            display: block;
            padding: 12px 20px;
            color: #ecf0f1;
            text-decoration: none;
            transition: all 0.3s;
        }

        .sidebar-nav li a:hover {
            background-color: rgba(255, 255, 255, 0.1);
        }

        .sidebar-nav li.active a {
            background-color: #3498db;
            color: white;
        }

        .sidebar-nav li a i {
            margin-right: 10px;
        }

        .main-content {
            flex: 1;
            display: flex;
            flex-direction: column;
        }

        .iframe-container {
            flex: 1;
            border: none;
        }

        iframe {
            width: 100%;
            height: 100%;
            border: none;
        }
    </style>
</head>
<body>
    <div class="container">
        <!-- 侧边导航栏 -->
        <div class="sidebar">
            <div class="sidebar-header">
                <h3>后台管理页面</h3>
            </div>
            <ul class="sidebar-nav">
                <li class="active">
                    <a href="#" data-src="/main" onclick="changeIframe(this)">
                        <i class="ly-icon ly-icon-home"></i> 首页
                    </a>
                </li>
                <li>
                    <a href="#" data-src="/user/list" onclick="changeIframe(this)">
                        <i class="ly-icon ly-icon-user"></i> 用户管理
                    </a>
                </li>
                <li>
                    <a href="#" data-src="/task/list" onclick="changeIframe(this)">
                        <i class="ly-icon ly-icon-settings"></i> 定时任务管理
                    </a>
                </li>
            </ul>
        </div>

        <!-- 主内容区 -->
        <div class="main-content">
            <div class="iframe-container">
                <iframe id="main-iframe" src="/main" frameborder="0"></iframe>
            </div>
        </div>
    </div>

    <!-- 引入 Laiyui JS -->
    <script src="../static/layui-v2.2.5/layui/layui.js"></script>
    <script>
        function changeIframe(element) {
            // 更新导航菜单的active状态
            document.querySelectorAll('.sidebar-nav li').forEach(li => {
                li.classList.remove('active');
            });
            element.parentElement.classList.add('active');

            // 更新iframe内容
            const iframe = document.getElementById('main-iframe');
            iframe.src = element.getAttribute('data-src');

            return false; // 阻止默认行为
        }
    </script>
</body>
</html>